#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : aimix
@File    : merge_audio_worker.py
@IDE     : PyCharm
@Author  : admin
@Date    : 2025/4/22 09:52
"""
import traceback
from multiprocessing import Process
from worker.base_worker import BaseThread

from core.audio.merge_audio import AudioMerger


class MergeAudioWorker(BaseThread):
    """合并音频线程"""
    def __init__(self, params, parent=None):
        super(MergeAudioWorker, self).__init__(params, parent)
        self.input_files = params['tasks']
        self.output_folder = params['output_path']

    def run(self):

        try:
            self.process = Process(target=AudioMerger(self.input_files, self.output_folder, self.queue).merge_audio, args=())
            self.process.start()
            while True:
                msg = self.queue.get()
                if msg == "done":
                    break
                self.on_change_progress(msg)

        except Exception as e:
            self.failed.emit(e)
            traceback.print_exc()